// var i;
// var AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
// var AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
// var AL_GAME_HUA_AwardConfig = require("./AL_GAME_HUA_AwardConfig");
// var AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
// var AL_GAME_HUA_GameData = require("./AL_GAME_HUA_GameData");
// var AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
// var AL_GAME_HUA_Instance = require("./AL_GAME_HUA_Instance");
// var AL_GAME_HUA_LevelConfig = require("./AL_GAME_HUA_LevelConfig");
// var AL_GAME_HUA_PropConfig = require("./AL_GAME_HUA_PropConfig");
// var AL_GAME_HUA_PlatformManager = require("./AL_GAME_HUA_PlatformManager");
// var AL_GAME_HUA_HomeBox = require("./AL_GAME_HUA_HomeBox");
// var AL_GAME_HUA_OnlineGiftConfig = require("./AL_GAME_HUA_OnlineGiftConfig");
// var AL_GAME_HUA_BankData = require("./AL_GAME_HUA_BankData");
// var AL_GAME_HUA_MissionConfig = require("./AL_GAME_HUA_MissionConfig");
// var AL_GAME_HUA_i18nMgr = require("./AL_GAME_HUA_i18nMgr");
// var AL_GAME_HUA_OnlineGiftData = require("./AL_GAME_HUA_OnlineGiftData");
// var AL_GAME_HUA_DateData = require("./AL_GAME_HUA_DateData");
// var AL_GAME_HUA_PayData = require("./AL_GAME_HUA_PayData");
// var AL_GAME_HUA_WelfareData = require("./AL_GAME_HUA_WelfareData");
// var w = cc._decorator;
// var Y = w.ccclass;
// var E = w.property;
// var A =
//     (w.menu,
//     (function (e) {
//         function t() {
//             var t = (null !== e && e.apply(this, arguments)) || this;
//             t.home_Button = null;
//             t.home_label = null;
//             t.challenge_Button = null;
//             t.special_Button = null;
//             t.level_Box = null;
//             t.star_Box = null;
//             t.mission_Button = null;
//             t.bank_Button = null;
//             t.online_Button = null;
//             t.node_button_share = null;
//             t.welfare_Button = null;
//             t.skin_Button = null;
//             t.side_Bar = null;
//             t.rank_Button = null;
//             t.onlineLabel = null;
//             t.onlineRedDot = null;
//             t.welfareRedDot = null;
//             return t;
//         }
//         __extends(t, e);
//         t.prototype.onLoad = function () {
//             return __awaiter(this, void 0, void 0, function () {
//                 var e = this;
//                 return __generator(this, function () {
//                     AL_GAME_HUA_Common.Common.xianshi_xiafang_guanggao();
//                     AL_APP_SDK_MANAGER.on(
//                         AL_GAME_HUA_Define.GameEvent.CHANGE_AWARD_NUM,
//                         function () {
//                             e.shuaxin_dengji_baoxiang();
//                         },
//                         this
//                     );
//                     this.chushihua_ui();
//                     return [2];
//                 });
//             });
//         };
//         t.prototype.start = function () {
//             window.miniMainGame;
//             AL_GAME_HUA_Define.Define.GAME_NAME;
//             this.home_Button.active = !1;
//             var e = cc.find("ageNode", this.node);
//             e.active = !0;
//             ailin_sdk_manager.xianshiShilingTishi({
//                 node: e
//             });
//             ailin_sdk_manager.addListenerBackKey({
//                 node: this.node
//             });
//         };
//         t.prototype.onDestroy = function () {
//             AL_APP_SDK_MANAGER.off(this);
//         };
//         t.prototype.handle_event_click_fanhui_zhuye = function () {
//             AL_GAME_HUA_Instance.Instance.huidao_shouye();
//         };
//         t.prototype.chushihua_ui = function () {
//             AL_GAME_HUA_GameData.GameData.getInstance().shezhi_dangqian_guanqia();
//             this.home_label.string = AL_GAME_HUA_i18nMgr.i18nMgr._huoqu_biaoqian("第x关", [
//                 AL_GAME_HUA_GameData.GameData.getInstance().huoqu_yijiesuo_guanqia().toString()
//             ]);
//             AL_GAME_HUA_Instance.Instance.xianshi_dingbu_tiao({
//                 target: this.node,
//                 showAll: !0
//             });
//             this.chushihua_pifu();
//             this.chushihua_baoxiang();
//             this.chushihua_zaixian_jiangli();
//             this.chushihua_yinhang();
//             this.chushihua_fuli();
//             this.chushihua_paihangbang();
//             this.side_Bar.active = "tt" == ailin_sdk_manager.getSysPlatformName();
//             var e = AL_GAME_HUA_GameData.GameData.getInstance();
//             AL_GAME_HUA_LevelConfig.LevelConfig.getInstance().huoqu_tiaozhan_guanqia_shifou_keyong()
//                 ? (this.challenge_Button.active = !0)
//                 : (this.challenge_Button.active = !1);
//             if (AL_GAME_HUA_LevelConfig.LevelConfig.getInstance().huoqu_teshu_guanqia_shifou_keyong()) {
//                 this.special_Button.active = !0;
//                 var t = cc.find("Background/level", this.special_Button).getComponent(cc.Label);
//                 var n = AL_GAME_HUA_LevelConfig.LevelConfig.getInstance().huoqu_teshu_guanqia_zong_shuliang();
//                 var o = Math.min(e.huoqu_yijiesuo_teshu_guanqia(), n);
//                 t.string = o + "/" + n;
//             } else {
//                 this.special_Button.active = !1;
//             }
//             if (AL_GAME_HUA_Instance.Instance.goMainCount > 1) {
//                 AL_GAME_HUA_DateData.DateData.getInstance().jiancha_riqi_he_zhou_shifou_xuyao_shuaxin();
//                 AL_GAME_HUA_PayData.PayData.getInstance().jiancha_zhifu_shuju();
//             }
//             AL_GAME_HUA_WelfareData.WelfareData.getInstance().chaxunYaoqingShuju();
//         };
//         t.prototype.jiancha_denglu_jiangli = function () {
//             if (
//                 AL_GAME_HUA_GameConst.GameConst.getInstance().login_gift_enabled &&
//                 "wx" === ailin_sdk_manager.getSysPlatformName()
//             ) {
//                 if (!AL_GAME_HUA_OnlineGiftData.OnlineGiftData.getInstance().dailyReward) {
//                     if (AL_GAME_HUA_OnlineGiftData.OnlineGiftData.getInstance().dailyRewardPop) {
//                         if (!(AL_GAME_HUA_Instance.Instance.goMainCount < 2)) {
//                             AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_denglulibao_mianban();
//                         }
//                     }
//                 }
//             }
//         };
//         t.prototype.chushihua_paihangbang = function () {
//             var e = AL_GAME_HUA_GameData.GameData.getInstance();
//             "tt" == ailin_sdk_manager.getSysPlatformName()
//                 ? (e.huoqu_xingxing_shuliang() > 0 &&
//                       AL_GAME_HUA_PlatformManager.PlatformManager.getInstance().tt.setImRankData({
//                           value: e.huoqu_xingxing_shuliang()
//                       }),
//                   (this.rank_Button.active = !0))
//                 : cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS
//                 ? (e.huoqu_xingxing_shuliang() > 0 && ailin_sdk_manager.shezhiPaihangbangShuju("score", e.huoqu_xingxing_shuliang()),
//                   (this.rank_Button.active = !0))
//                 : "wx" == ailin_sdk_manager.getSysPlatformName() &&
//                   (ailin_sdk_manager.tijiaoPaihangbangFenshu &&
//                       ailin_sdk_manager.tijiaoPaihangbangFenshu({
//                           data: {
//                               score: e.huoqu_xingxing_shuliang()
//                           },
//                           success: function () {
//                               console.log("微信得分提交成功");
//                           }
//                       }),
//                   (this.rank_Button.active = !1));
//         };
//         t.prototype.chushihua_pifu = function () {
//             this.skin_Button.active = AL_GAME_HUA_GameConst.GameConst.getInstance().skin_enabled;
//         };
//         t.prototype.chushihua_baoxiang = function () {
//             var e = this;
//             this.level_Box.chuli_lingqu = function () {
//                 AL_GAME_HUA_AddPrefab.AddPrefab.create_award({
//                     type: AL_GAME_HUA_Define.Define.AwardType.LEVEL,
//                     chuli_lingqu: function () {
//                         e.shuaxin_dengji_baoxiang();
//                     }
//                 });
//                 AL_GAME_HUA_MissionConfig.MissionConfig.getInstance().tianjia_renwu_shuliang_by_leixing(
//                     AL_GAME_HUA_MissionConfig.MissionType.BOX_RECIEVED
//                 );
//             };
//             this.star_Box.chuli_lingqu = function () {
//                 AL_GAME_HUA_AddPrefab.AddPrefab.create_award({
//                     type: AL_GAME_HUA_Define.Define.AwardType.STAR,
//                     chuli_lingqu: function () {
//                         e.shuaxin_xingxing_baoxiang();
//                     }
//                 });
//                 AL_GAME_HUA_MissionConfig.MissionConfig.getInstance().tianjia_renwu_shuliang_by_leixing(
//                     AL_GAME_HUA_MissionConfig.MissionType.STAR_BOX_RECIEVE
//                 );
//             };
//             this.shuaxin_dengji_baoxiang();
//             this.shuaxin_xingxing_baoxiang();
//         };
//         t.prototype.chushihua_yinhang = function () {
//             if (AL_GAME_HUA_GameConst.GameConst.getInstance().money_enabled) {
//                 this.bank_Button.active = !0;
//                 var e = this.bank_Button.getChildByName("node_red_dot");
//                 e.active =
//                     AL_GAME_HUA_BankData.BankData.getInstance().huoqu_cunchu_de_jinqian() >=
//                     AL_GAME_HUA_GameConst.GameConst.getInstance().money_valid;
//                 AL_APP_SDK_MANAGER.on(
//                     AL_GAME_HUA_Define.GameEvent.ON_BANK_MONEY_CHANGE,
//                     function () {
//                         e.active =
//                             AL_GAME_HUA_BankData.BankData.getInstance().huoqu_cunchu_de_jinqian() >=
//                             AL_GAME_HUA_GameConst.GameConst.getInstance().money_valid;
//                     },
//                     this
//                 );
//             } else {
//                 this.bank_Button.active = !1;
//             }
//         };
//         t.prototype.chushihua_renwu = function () {
//             if (AL_GAME_HUA_GameConst.GameConst.getInstance().mission_enabled) {
//                 this.mission_Button.active = !0;
//                 var e = this.mission_Button.getChildByName("node_red_dot");
//                 e.active =
//                     AL_GAME_HUA_MissionConfig.MissionConfig.getInstance().huoqu_meiri_renwu_shifou_wancheng() ||
//                     AL_GAME_HUA_MissionConfig.MissionConfig.getInstance().huoqu_changzhu_renwu_shifou_wancheng();
//                 AL_APP_SDK_MANAGER.on(
//                     AL_GAME_HUA_Define.GameEvent.ON_MISSION_CHANGE,
//                     function () {
//                         e.active =
//                             AL_GAME_HUA_MissionConfig.MissionConfig.getInstance().huoqu_meiri_renwu_shifou_wancheng() ||
//                             AL_GAME_HUA_MissionConfig.MissionConfig.getInstance().huoqu_changzhu_renwu_shifou_wancheng();
//                     },
//                     this
//                 );
//             } else {
//                 this.mission_Button.active = !1;
//             }
//         };
//         t.prototype.chushihua_fenxiang = function () {};
//         t.prototype.chushihua_fuli = function () {
//             var e = this;
//             "wx" == ailin_sdk_manager.getSysPlatformName()
//                 ? ((this.welfare_Button.active = !0),
//                   (this.welfareRedDot = this.welfare_Button.getChildByName("node_red_dot")),
//                   (this.welfareRedDot.active = AL_GAME_HUA_WelfareData.WelfareData.getInstance().huoqu_shifou_yongyou_renyi_fuli_jiangli()),
//                   AL_APP_SDK_MANAGER.on(
//                       AL_GAME_HUA_Define.GameEvent.REFRESH_INVITE_LIST,
//                       function () {
//                           e.welfareRedDot.active =
//                               AL_GAME_HUA_WelfareData.WelfareData.getInstance().huoqu_shifou_yongyou_renyi_fuli_jiangli();
//                       },
//                       this
//                   ),
//                   AL_APP_SDK_MANAGER.on(
//                       AL_GAME_HUA_Define.GameEvent.ON_DAILY_SHARE_REFRESH,
//                       function () {
//                           e.welfareRedDot.active =
//                               AL_GAME_HUA_WelfareData.WelfareData.getInstance().huoqu_shifou_yongyou_renyi_fuli_jiangli();
//                       },
//                       this
//                   ),
//                   AL_APP_SDK_MANAGER.on(
//                       AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_REFRESH,
//                       function () {
//                           e.welfareRedDot.active =
//                               AL_GAME_HUA_WelfareData.WelfareData.getInstance().huoqu_shifou_yongyou_renyi_fuli_jiangli();
//                       },
//                       this
//                   ),
//                   AL_APP_SDK_MANAGER.on(
//                       AL_GAME_HUA_Define.GameEvent.ON_SUBSCRIBE_REFRESH,
//                       function () {
//                           e.welfareRedDot.active =
//                               AL_GAME_HUA_WelfareData.WelfareData.getInstance().huoqu_shifou_yongyou_renyi_fuli_jiangli();
//                       },
//                       this
//                   ))
//                 : (this.welfare_Button.active = !1);
//         };
//         t.prototype.chushihua_zaixian_jiangli = function () {
//             var e = this;
//             AL_GAME_HUA_GameConst.GameConst.getInstance().online_enabled
//                 ? ((this.online_Button.active = !0),
//                   (this.onlineLabel = this.online_Button.getChildByName("label").getComponent(cc.Label)),
//                   (this.onlineRedDot = this.online_Button.getChildByName("node_red_dot")),
//                   (this.onlineRedDot.active =
//                       AL_GAME_HUA_OnlineGiftConfig.OnlineGiftConfig.getInstance().huoqu_zaixian_jiangli_shifou_jiesuo()),
//                   AL_APP_SDK_MANAGER.on(
//                       AL_GAME_HUA_Define.GameEvent.ONLINE_GIFT_UNLOCK,
//                       function () {
//                           e.onlineRedDot.active =
//                               AL_GAME_HUA_OnlineGiftConfig.OnlineGiftConfig.getInstance().huoqu_zaixian_jiangli_shifou_jiesuo();
//                       },
//                       this
//                   ))
//                 : (this.online_Button.active = !1);
//         };
//         t.prototype.shuaxin_zaixian_biaoqian = function () {
//             if (this.onlineLabel) {
//                 this.onlineLabel.string = AL_GAME_HUA_Common.Common.geshihua_shijian(
//                     1e3 * AL_GAME_HUA_OnlineGiftConfig.OnlineGiftConfig.getInstance().huoqu_shengyu_shijian(),
//                     !0
//                 );
//             }
//         };
//         t.prototype.shuaxin_dengji_baoxiang = function () {
//             var e = AL_GAME_HUA_GameData.GameData.getInstance();
//             var t = e.huoqu_jiangli_shuliang();
//             var n = AL_GAME_HUA_AwardConfig.AwardConfig.getInstance();
//             var o = n.genju_jishu_huoqu_jianli_xinxi(t);
//             var i = 0 == t ? 0 : n.genju_jishu_huoqu_jianli_xinxi(t - 1).level;
//             this.level_Box.shuaxin_jindu(e.huoqu_yijiesuo_guanqia() - 1 + e.huoqu_yijiesuo_teshu_guanqia() - 1 - i, o.level - i);
//             this.level_Box.shuaxin_jiangli(o);
//         };
//         t.prototype.shuaxin_xingxing_baoxiang = function () {
//             var e = AL_GAME_HUA_GameData.GameData.getInstance();
//             var t = e.huoqu_xingxing_hezi_shuliang();
//             var n = AL_GAME_HUA_AwardConfig.AwardConfig.getInstance();
//             var o = n.genju_jishu_huoqu_xingji_jianli_xinxi(t);
//             var i = 0 == t ? 0 : n.genju_jishu_huoqu_xingji_jianli_xinxi(t - 1).level;
//             this.star_Box.shuaxin_jindu(e.huoqu_xingxing_shuliang() - i, o.level - i);
//             this.star_Box.shuaxin_jiangli(o);
//         };
//         t.prototype.chuli_dianji_jinru_youxi = function () {
//             AL_GAME_HUA_Instance.Instance.jiancha_tili_shifou_zugou(function () {
//                 AL_GAME_HUA_Instance.Instance.qianwang_youxi();
//             });
//         };
//         t.prototype.kaishi_putong_guanqia = function () {
//             AL_GAME_HUA_Instance.Instance.LevelType = AL_GAME_HUA_Define.Define.LevelType.NORMAL;
//             AL_GAME_HUA_GameData.GameData.getInstance().huoqu_yijiesuo_guanqia() <=
//             AL_GAME_HUA_GameConst.GameConst.getInstance().prop_pop_level[0]
//                 ? this.chuli_dianji_jinru_youxi()
//                 : AL_GAME_HUA_AddPrefab.AddPrefab.create_prop_start();
//         };
//         t.prototype.handle_click_button = function (e, t) {
//             switch (t) {
//                 case "list":
//                     cc.sys.isNative && cc.sys.os == cc.sys.OS_IOS
//                         ? ailin_sdk_manager.xianshiSuoyouPaipingCeng()
//                         : "tt" == ailin_sdk_manager.getSysPlatformName() &&
//                           AL_GAME_HUA_PlatformManager.PlatformManager.getInstance().tt.getRankEnabled()
//                         ? AL_GAME_HUA_PlatformManager.PlatformManager.getInstance().tt.getImRankList({
//                               rankTitle: "星星排行榜",
//                               suffix: "星"
//                           })
//                         : "wx" == ailin_sdk_manager.getSysPlatformName() && ailin_sdk_manager.xianshiPaihangbangYemian
//                         ? ailin_sdk_manager.xianshiPaihangbangYemian({
//                               title: "星星排行榜",
//                               key: "score"
//                           })
//                         : AL_GAME_HUA_AddPrefab.AddPrefab.createList();
//                     break;
//                 case "shop":
//                     AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_shangdian_mianban({
//                         parent: this.node
//                     });
//                     break;
//                 case "setting":
//                     AL_GAME_HUA_AddPrefab.AddPrefab.create_setting({
//                         isGame: !1
//                     });
//                     break;
//                 case "start":
//                     this.kaishi_putong_guanqia();
//                     break;
//                 case "challenge":
//                     AL_GAME_HUA_AddPrefab.AddPrefab.create_challenge();
//                     break;
//                 case "special":
//                     AL_GAME_HUA_LevelConfig.LevelConfig.getInstance().huoqu_teshu_guanqia_shifou_jiesuo()
//                         ? ((AL_GAME_HUA_Instance.Instance.LevelType = AL_GAME_HUA_Define.Define.LevelType.SPECIAL),
//                           AL_GAME_HUA_PropConfig.PropConfig.getInstance().huoqu_shuxing_jinru_xianshi()
//                               ? AL_GAME_HUA_AddPrefab.AddPrefab.create_prop_start()
//                               : this.chuli_dianji_jinru_youxi())
//                         : AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_tishi_jiedian_mianban({
//                               str: "通过x关解锁",
//                               params: [AL_GAME_HUA_GameConst.GameConst.getInstance().special_unlock_level.toString()]
//                           });
//                     break;
//                 case "award":
//                     var n = AL_GAME_HUA_GameData.GameData.getInstance(),
//                         o = AL_GAME_HUA_AwardConfig.AwardConfig.getInstance();
//                     n.huoqu_yijiesuo_guanqia() / o.genju_jishu_huoqu_jianli_xinxi(n.huoqu_jiangli_shuliang()).level >= 1
//                         ? AL_GAME_HUA_AddPrefab.AddPrefab.create_award({
//                               type: AL_GAME_HUA_Define.Define.AwardType.LEVEL,
//                               chuli_lingqu: function () {}
//                           })
//                         : AL_GAME_HUA_AddPrefab.AddPrefab.create_award_label({
//                               parent: this.node
//                           });
//                     break;
//                 case "addgold":
//                     AL_GAME_HUA_AddPrefab.AddPrefab.create_add_gold();
//                     break;
//                 case "bank":
//                     AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_yinhang_mianban();
//                     break;
//                 case "mission":
//                     AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_renwu_mianban();
//                     break;
//                 case "online":
//                     AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_zaixianlibao_mianban();
//                     break;
//                 case "share":
//                     AL_GAME_HUA_Common.Common.share({
//                         location: AL_GAME_HUA_Define.Define.SHARE_LOCATION.HOME,
//                         type: 1
//                     });
//                     break;
//                 case "welfare":
//                     AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_fuli_mianban();
//             }
//         };
//         t.prototype.update = function () {
//             this.shuaxin_zaixian_biaoqian();
//         };
//         __decorate(
//             [
//                 E({
//                     type: cc.Node,
//                     tooltip: ""
//                 })
//             ],
//             t.prototype,
//             "home_Button",
//             void 0
//         );
//         __decorate([E(cc.Label)], t.prototype, "home_label", void 0);
//         __decorate([E(cc.Node)], t.prototype, "challenge_Button", void 0);
//         __decorate([E(cc.Node)], t.prototype, "special_Button", void 0);
//         __decorate([E(AL_GAME_HUA_HomeBox.default)], t.prototype, "level_Box", void 0);
//         __decorate([E(AL_GAME_HUA_HomeBox.default)], t.prototype, "star_Box", void 0);
//         __decorate([E(cc.Node)], t.prototype, "mission_Button", void 0);
//         __decorate([E(cc.Node)], t.prototype, "bank_Button", void 0);
//         __decorate([E(cc.Node)], t.prototype, "online_Button", void 0);
//         __decorate([E(cc.Node)], t.prototype, "node_button_share", void 0);
//         __decorate([E(cc.Node)], t.prototype, "welfare_Button", void 0);
//         __decorate([E(cc.Node)], t.prototype, "skin_Button", void 0);
//         __decorate([E(cc.Node)], t.prototype, "side_Bar", void 0);
//         __decorate([E(cc.Node)], t.prototype, "rank_Button", void 0);
//         return __decorate([Y], t);
//     })(cc.Component));
// exports.default = A;


const AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
const AL_GAME_HUA_Define = require("./AL_GAME_HUA_Define");
const AL_GAME_HUA_AwardConfig = require("./AL_GAME_HUA_AwardConfig");
const AL_GAME_HUA_GameConst = require("./AL_GAME_HUA_GameConst");
const AL_GAME_HUA_GameData = require("./AL_GAME_HUA_GameData");
const AL_GAME_HUA_AddPrefab = require("./AL_GAME_HUA_AddPrefab");
const AL_GAME_HUA_Instance = require("./AL_GAME_HUA_Instance");
const AL_GAME_HUA_LevelConfig = require("./AL_GAME_HUA_LevelConfig");
const AL_GAME_HUA_PropConfig = require("./AL_GAME_HUA_PropConfig");
const AL_GAME_HUA_PlatformManager = require("./AL_GAME_HUA_PlatformManager");
const AL_GAME_HUA_HomeBox = require("./AL_GAME_HUA_HomeBox");
const AL_GAME_HUA_OnlineGiftConfig = require("./AL_GAME_HUA_OnlineGiftConfig");
const AL_GAME_HUA_BankData = require("./AL_GAME_HUA_BankData");
const AL_GAME_HUA_MissionConfig = require("./AL_GAME_HUA_MissionConfig");
const AL_GAME_HUA_i18nMgr = require("./AL_GAME_HUA_i18nMgr");
const AL_GAME_HUA_OnlineGiftData = require("./AL_GAME_HUA_OnlineGiftData");
const AL_GAME_HUA_DateData = require("./AL_GAME_HUA_DateData");
const AL_GAME_HUA_PayData = require("./AL_GAME_HUA_PayData");
const AL_GAME_HUA_WelfareData = require("./AL_GAME_HUA_WelfareData");
const { AL_SDK_Utils } = require("../../resources/scripts/AL_SDK_Utils");

const { ccclass, property } = cc._decorator;

/**
 * 主界面管理类
 */
@ccclass
class MainScene extends cc.Component {
    @property({ type: cc.Node, tooltip: "" })
    home_Button = null;
    
    @property(cc.Label)
    home_label = null;
    
    @property(cc.Node)
    challenge_Button = null;

    @property(cc.Node)
    special_Button = null;

    @property(AL_GAME_HUA_HomeBox.default)
    level_Box = null;

    @property(AL_GAME_HUA_HomeBox.default)
    star_Box = null;
    
    @property(cc.Node)
    mission_Button = null;

    @property(cc.Node)
    bank_Button = null;

    @property(cc.Node)
    online_Button = null;

    @property(cc.Node)
    node_button_share = null;

    @property(cc.Node)
    welfare_Button = null;
    
    @property(cc.Node)
    skin_Button = null;
    
    @property(cc.Node)
    side_Bar = null;
    
    @property(cc.Node)
    rank_Button = null;

    /**
     * 加载完成事件处理
     */
    async onLoad() {
        AL_GAME_HUA_Common.Common.xianshi_xiafang_guanggao();
        AL_APP_SDK_MANAGER.on(
            AL_GAME_HUA_Define.GameEvent.CHANGE_AWARD_NUM,
            () => this.shuaxin_dengji_baoxiang(),
            this
        );
        this.chushihua_ui();
    }

    /**
     * 组件启动事件处理
     */
    start() {
        window.miniMainGame;
        AL_GAME_HUA_Define.Define.GAME_NAME;
        this.home_Button.active = false;
        // let ageNode = cc.find("ageNode", this.node);
        // ageNode.active = true;
        //ailin_sdk_manager.xianshiShilingTishi({ node: ageNode });
        ailin_sdk_manager.addListenerBackKey({ node: this.node });
    }

    /**
     * 组件销毁事件处理
     */
    onDestroy() {
        AL_APP_SDK_MANAGER.off(this);
    }

    /**
     * 返回主页按钮点击事件处理
     */
    handle_event_click_fanhui_zhuye() {
        AL_GAME_HUA_Instance.Instance.huidao_shouye();
    }

    /**
     * 初始化UI
     */
    chushihua_ui() {


        AL_GAME_HUA_GameData.GameData.getInstance().shezhi_dangqian_guanqia();
        this.home_label.string = AL_GAME_HUA_i18nMgr.i18nMgr._huoqu_biaoqian("第x关", [
            AL_GAME_HUA_GameData.GameData.getInstance().huoqu_yijiesuo_guanqia().toString()
        ]);
        AL_GAME_HUA_Instance.Instance.xianshi_dingbu_tiao({
            target: this.node,
            showAll: !0
        });
        this.chushihua_pifu();
        this.chushihua_baoxiang();
        this.chushihua_zaixian_jiangli();
        this.chushihua_yinhang();
        this.chushihua_fuli();
        this.chushihua_paihangbang();
        this.side_Bar.active = "tt" == ailin_sdk_manager.getSysPlatformName();
        var e = AL_GAME_HUA_GameData.GameData.getInstance();
        AL_GAME_HUA_LevelConfig.LevelConfig.getInstance().huoqu_tiaozhan_guanqia_shifou_keyong()
            ? (this.challenge_Button.active = !0)
            : (this.challenge_Button.active = !1);
        if (AL_GAME_HUA_LevelConfig.LevelConfig.getInstance().huoqu_teshu_guanqia_shifou_keyong()) {
            this.special_Button.active = !0;
            var t = cc.find("Background/level", this.special_Button).getComponent(cc.Label);
            var n = AL_GAME_HUA_LevelConfig.LevelConfig.getInstance().huoqu_teshu_guanqia_zong_shuliang();
            var o = Math.min(e.huoqu_yijiesuo_teshu_guanqia(), n);
            t.string = o + "/" + n;
        } else {
            this.special_Button.active = !1;
        }
        if (AL_GAME_HUA_Instance.Instance.goMainCount > 1) {
            AL_GAME_HUA_DateData.DateData.getInstance().jiancha_riqi_he_zhou_shifou_xuyao_shuaxin();
            AL_GAME_HUA_PayData.PayData.getInstance().jiancha_zhifu_shuju();
        }
        AL_GAME_HUA_WelfareData.WelfareData.getInstance().chaxunYaoqingShuju();

        AL_SDK_Utils.loadBanner();
        AL_SDK_Utils.loadInterAd();
        // const gameData = AL_GAME_HUA_GameData.GameData.getInstance();
        // gameData.shezhi_dangqian_guanqia();
        
        // this.home_label.string = AL_GAME_HUA_i18nMgr.i18nMgr._huoqu_biaoqian("第x关", [
        //     gameData.huoqu_yijiesuo_guanqia().toString()
        // ]);
        
        // AL_GAME_HUA_Instance.Instance.xianshi_dingbu_tiao({
        //     target: this.node,
        //     showAll: true
        // });
        
        // this.chushihua_pifu();
        // this.chushihua_baoxiang();
        // this.chushihua_zaixian_jiangli();
        // this.chushihua_yinhang();
        // this.chushihua_fuli();
        // this.chushihua_paihangbang();

        // this.side_Bar.active = "tt" === ailin_sdk_manager.getSysPlatformName();

        // const levelConfig = AL_GAME_HUA_LevelConfig.LevelConfig.getInstance();
        
        // this.challenge_Button.active = levelConfig.huoqu_tiaozhan_guanqia_shifou_keyong();

        // if (levelConfig.huoqu_teshu_guanqia_shifou_keyong()) {
        //     this.special_Button.active = true;
        //     const specialButtonLabel = cc.find("Background/level", this.special_Button).getComponent(cc.Label);
        //     const totalSpecialLevels = levelConfig.huoqu_teshu_guanqia_zong_shuliang();
        //     const unlockedSpecialLevel = Math.min(gameData.huoqu_yijiesuo_teshu_guanqia(), totalSpecialLevels);
        //     specialButtonLabel.string = `${unlockedSpecialLevel}/${totalSpecialLevels}`;
        // } else {
        //     this.special_Button.active = false;
        // }

        // if (AL_GAME_HUA_Instance.Instance.goMainCount > 1) {
        //     AL_GAME_HUA_DateData.DateData.getInstance().jiancha_riqi_he_zhou_shifou_xuyao_shuaxin();
        //     AL_GAME_HUA_PayData.PayData.getInstance().jiancha_zhifu_shuju();
        // }
        // AL_GAME_HUA_WelfareData.WelfareData.getInstance().chaxunYaoqingShuju();
    }

    /**
     * 检查登录奖励
     */
    jiancha_denglu_jiangli() {
        if (
            AL_GAME_HUA_GameConst.GameConst.getInstance().login_gift_enabled &&
            "wx" === ailin_sdk_manager.getSysPlatformName()
        ) {
            const onlineGiftData = AL_GAME_HUA_OnlineGiftData.OnlineGiftData.getInstance();
            if (!onlineGiftData.dailyReward) {
                if (onlineGiftData.dailyRewardPop) {
                    if (!(AL_GAME_HUA_Instance.Instance.goMainCount < 2)) {
                        AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_denglulibao_mianban();
                    }
                }
            }
        }
    }

    /**
     * 初始化排行榜
     */
    chushihua_paihangbang() {
        const gameData = AL_GAME_HUA_GameData.GameData.getInstance();
        const platformName = ailin_sdk_manager.getSysPlatformName();

        if (platformName === "tt") {
            if (gameData.huoqu_xingxing_shuliang() > 0) {
                AL_GAME_HUA_PlatformManager.PlatformManager.getInstance().tt.setImRankData({ value: gameData.huoqu_xingxing_shuliang() });
            }
            this.rank_Button.active = true;
        } else if (cc.sys.isNative && cc.sys.os === cc.sys.OS_IOS) {
            if (gameData.huoqu_xingxing_shuliang() > 0) {
                ailin_sdk_manager.shezhiPaihangbangShuju("score", gameData.huoqu_xingxing_shuliang());
            }
            this.rank_Button.active = true;
        } else if (platformName === "wx") {
            if (ailin_sdk_manager.tijiaoPaihangbangFenshu) {
                ailin_sdk_manager.tijiaoPaihangbangFenshu({
                    data: { score: gameData.huoqu_xingxing_shuliang() },
                    success: () => console.log("微信得分提交成功")
                });
            }
            this.rank_Button.active = false;
        }
    }

    /**
     * 初始化皮肤系统
     */
    chushihua_pifu() {
        this.skin_Button.active = AL_GAME_HUA_GameConst.GameConst.getInstance().skin_enabled;
    }

    /**
     * 初始化宝箱
     */
    chushihua_baoxiang() {
        this.level_Box.chuli_lingqu = () => {
            AL_GAME_HUA_AddPrefab.AddPrefab.create_award({
                type: AL_GAME_HUA_Define.Define.AwardType.LEVEL,
                chuli_lingqu: () => this.shuaxin_dengji_baoxiang()
            });
            AL_GAME_HUA_MissionConfig.MissionConfig.getInstance().tianjia_renwu_shuliang_by_leixing(AL_GAME_HUA_MissionConfig.MissionType.BOX_RECIEVED);
        };

        this.star_Box.chuli_lingqu = () => {
            AL_GAME_HUA_AddPrefab.AddPrefab.create_award({
                type: AL_GAME_HUA_Define.Define.AwardType.STAR,
                chuli_lingqu: () => this.shuaxin_xingxing_baoxiang()
            });
            AL_GAME_HUA_MissionConfig.MissionConfig.getInstance().tianjia_renwu_shuliang_by_leixing(AL_GAME_HUA_MissionConfig.MissionType.STAR_BOX_RECIEVE);
        };

        this.shuaxin_dengji_baoxiang();
        this.shuaxin_xingxing_baoxiang();
    }

    /**
     * 初始化银行系统
     */
    chushihua_yinhang() {
        if (AL_GAME_HUA_GameConst.GameConst.getInstance().money_enabled) {
            this.bank_Button.active = true;
            const node_red_dot = this.bank_Button.getChildByName("node_red_dot");
            node_red_dot.active =
                AL_GAME_HUA_BankData.BankData.getInstance().huoqu_cunchu_de_jinqian() >=
                AL_GAME_HUA_GameConst.GameConst.getInstance().money_valid;
            AL_APP_SDK_MANAGER.on(
                AL_GAME_HUA_Define.GameEvent.ON_BANK_MONEY_CHANGE,
                () => {
                    node_red_dot.active =
                        AL_GAME_HUA_BankData.BankData.getInstance().huoqu_cunchu_de_jinqian() >=
                        AL_GAME_HUA_GameConst.GameConst.getInstance().money_valid;
                },
                this
            );
        } else {
            this.bank_Button.active = false;
        }
    }

    /**
     * 初始化任务系统
     */
    chushihua_renwu() {
        if (AL_GAME_HUA_GameConst.GameConst.getInstance().mission_enabled) {
            this.mission_Button.active = true;
            const node_red_dot = this.mission_Button.getChildByName("node_red_dot");
            node_red_dot.active =
                AL_GAME_HUA_MissionConfig.MissionConfig.getInstance().huoqu_meiri_renwu_shifou_wancheng() ||
                AL_GAME_HUA_MissionConfig.MissionConfig.getInstance().huoqu_changzhu_renwu_shifou_wancheng();
            AL_APP_SDK_MANAGER.on(
                AL_GAME_HUA_Define.GameEvent.ON_MISSION_CHANGE,
                () => {
                    node_red_dot.active =
                        AL_GAME_HUA_MissionConfig.MissionConfig.getInstance().huoqu_meiri_renwu_shifou_wancheng() ||
                        AL_GAME_HUA_MissionConfig.MissionConfig.getInstance().huoqu_changzhu_renwu_shifou_wancheng();
                },
                this
            );
        } else {
            this.mission_Button.active = false;
        }
    }

    /**
     * 初始化分享功能
     */
    chushihua_fenxiang() {}

    /**
     * 初始化福利系统
     */
    chushihua_fuli() {
        const platformName = ailin_sdk_manager.getSysPlatformName();
        console.log("初始化福利系统：",platformName)
        if (platformName === "wx") {
            this.welfare_Button.active = true;
            this.welfareRedDot = this.welfare_Button.getChildByName("node_red_dot");
            this.welfareRedDot.active = AL_GAME_HUA_WelfareData.WelfareData.getInstance().huoqu_shifou_yongyou_renyi_fuli_jiangli();
            
            const updateWelfareRedDot = () => {
                this.welfareRedDot.active = AL_GAME_HUA_WelfareData.WelfareData.getInstance().huoqu_shifou_yongyou_renyi_fuli_jiangli();
            };

            const updateEvents = [
                AL_GAME_HUA_Define.GameEvent.REFRESH_INVITE_LIST,
                AL_GAME_HUA_Define.GameEvent.ON_DAILY_SHARE_REFRESH,
                AL_GAME_HUA_Define.GameEvent.ON_GAME_CLUB_REFRESH,
                AL_GAME_HUA_Define.GameEvent.ON_SUBSCRIBE_REFRESH,
            ];
            
            updateEvents.forEach(eventName => {
                AL_APP_SDK_MANAGER.on(eventName, updateWelfareRedDot, this);
            });
        } else {
            this.welfare_Button.active = false;
        }
    }

    /**
     * 初始化在线礼物系统
     */
    chushihua_zaixian_jiangli() {
        const gameConst = AL_GAME_HUA_GameConst.GameConst.getInstance();
        
        if (gameConst.online_enabled) {
            this.online_Button.active = true;
            this.onlineLabel = this.online_Button.getChildByName("label").getComponent(cc.Label);
            this.onlineRedDot = this.online_Button.getChildByName("node_red_dot");
            this.onlineRedDot.active = AL_GAME_HUA_OnlineGiftConfig.OnlineGiftConfig.getInstance().huoqu_zaixian_jiangli_shifou_jiesuo();

            AL_APP_SDK_MANAGER.on(
                AL_GAME_HUA_Define.GameEvent.ONLINE_GIFT_UNLOCK,
                () => {
                    this.onlineRedDot.active = AL_GAME_HUA_OnlineGiftConfig.OnlineGiftConfig.getInstance().huoqu_zaixian_jiangli_shifou_jiesuo();
                },
                this
            );
        } else {
            this.online_Button.active = false;
        }
    }

    /**
     * 刷新在线标签
     */
    shuaxin_zaixian_biaoqian() {
        if (this.onlineLabel) {
            this.onlineLabel.string = AL_GAME_HUA_Common.Common.geshihua_shijian(
                1e3 * AL_GAME_HUA_OnlineGiftConfig.OnlineGiftConfig.getInstance().huoqu_shengyu_shijian(),
                true
            );
        }
    }

    /**
     * 刷新等级宝箱
     */
    shuaxin_dengji_baoxiang() {
        const gameData = AL_GAME_HUA_GameData.GameData.getInstance();
        const awardCount = gameData.huoqu_jiangli_shuliang();
        const awardConfig = AL_GAME_HUA_AwardConfig.AwardConfig.getInstance();
        const awardInfo = awardConfig.genju_jishu_huoqu_jianli_xinxi(awardCount);

        const prevLevel = awardCount === 0 ? 0 : awardConfig.genju_jishu_huoqu_jianli_xinxi(awardCount - 1).level;
        this.level_Box.shuaxin_jindu(
            gameData.huoqu_yijiesuo_guanqia() - 1 + gameData.huoqu_yijiesuo_teshu_guanqia() - prevLevel,
            awardInfo.level - prevLevel
        );
        this.level_Box.shuaxin_jiangli(awardInfo);
    }

    /**
     * 刷新星星宝箱
     */
    shuaxin_xingxing_baoxiang() {
        const gameData = AL_GAME_HUA_GameData.GameData.getInstance();
        const starCount = gameData.huoqu_xingxing_hezi_shuliang();
        const awardConfig = AL_GAME_HUA_AwardConfig.AwardConfig.getInstance();
        const starAwardInfo = awardConfig.genju_jishu_huoqu_xingji_jianli_xinxi(starCount);
        
        const prevLevel = starCount === 0 ? 0 : awardConfig.genju_jishu_huoqu_xingji_jianli_xinxi(starCount - 1).level;
        this.star_Box.shuaxin_jindu(gameData.huoqu_xingxing_shuliang() - prevLevel, starAwardInfo.level - prevLevel);
        this.star_Box.shuaxin_jiangli(starAwardInfo);
    }

    /**
     * 点击进入游戏按钮
     */
    chuli_dianji_jinru_youxi() {
        AL_GAME_HUA_Instance.Instance.jiancha_tili_shifou_zugou(() => {
            AL_GAME_HUA_Instance.Instance.qianwang_youxi();
        });
    }

    /**
     * 开始普通关卡
     */
    kaishi_putong_guanqia() {
        AL_GAME_HUA_Instance.Instance.LevelType = AL_GAME_HUA_Define.Define.LevelType.NORMAL;
        const gameData = AL_GAME_HUA_GameData.GameData.getInstance();
        const gameConst = AL_GAME_HUA_GameConst.GameConst.getInstance();

        
        if (gameData.huoqu_yijiesuo_guanqia() > gameConst.prop_pop_level[0]) {
            AL_GAME_HUA_AddPrefab.AddPrefab.create_prop_start();
        } else {
            this.chuli_dianji_jinru_youxi();
        }
    }

    /**
     * 处理按钮点击事件
     * @param {*} event 
     * @param {*} buttonType 
     */
    handle_click_button(event, buttonType) {
        switch (buttonType) {
            case "list":
                if (cc.sys.isNative && cc.sys.os === cc.sys.OS_IOS) {
                    ailin_sdk_manager.xianshiSuoyouPaipingCeng();
                } else if (ailin_sdk_manager.getSysPlatformName() === "tt" && AL_GAME_HUA_PlatformManager.PlatformManager.getInstance().tt.getRankEnabled()) {
                    AL_GAME_HUA_PlatformManager.PlatformManager.getInstance().tt.getImRankList({
                        rankTitle: "星星排行榜",
                        suffix: "星"
                    });
                } else if (ailin_sdk_manager.getSysPlatformName() === "wx" && ailin_sdk_manager.xianshiPaihangbangYemian) {
                    ailin_sdk_manager.xianshiPaihangbangYemian({
                        title: "星星排行榜",
                        key: "score"
                    });
                } else {
                    AL_GAME_HUA_AddPrefab.AddPrefab.createList();
                }
                break;
            case "shop":
                AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_shangdian_mianban({
                    parent: this.node
                });
                break;
            case "setting":
                AL_GAME_HUA_AddPrefab.AddPrefab.create_setting({
                    isGame: false
                });
                break;
            case "start":
                this.kaishi_putong_guanqia();
                break;
            case "challenge":
                AL_GAME_HUA_AddPrefab.AddPrefab.create_challenge();
                break;
            case "special":
                const levelConfig = AL_GAME_HUA_LevelConfig.LevelConfig.getInstance();
                                             
                if (levelConfig.huoqu_teshu_guanqia_shifou_jiesuo()) {
                    AL_GAME_HUA_Instance.Instance.LevelType = AL_GAME_HUA_Define.Define.LevelType.SPECIAL;
                    const propConfig = AL_GAME_HUA_PropConfig.PropConfig.getInstance();
                    
                    if (propConfig.huoqu_shuxing_jinru_xianshi()) {
                        AL_GAME_HUA_AddPrefab.AddPrefab.create_prop_start();
                    } else {
                        this.chuli_dianji_jinru_youxi();
                    }
                } else {
                    AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_tishi_jiedian_mianban({
                        str: "通过x关解锁",
                        params: [AL_GAME_HUA_GameConst.GameConst.getInstance().special_unlock_level.toString()]
                    });
                }
                break;
            case "award":
                const gameData = AL_GAME_HUA_GameData.GameData.getInstance();
                const awardConfig = AL_GAME_HUA_AwardConfig.AwardConfig.getInstance();
                
                if (gameData.huoqu_yijiesuo_guanqia() / awardConfig.genju_jishu_huoqu_jianli_xinxi(gameData.huoqu_jiangli_shuliang()).level >= 1) {
                    AL_GAME_HUA_AddPrefab.AddPrefab.create_award({
                        type: AL_GAME_HUA_Define.Define.AwardType.LEVEL,
                        chuli_lingqu: () => {}
                    });
                } else {
                    AL_GAME_HUA_AddPrefab.AddPrefab.create_award_label({
                        parent: this.node
                    });
                }
                break;
            case "addgold":
                AL_GAME_HUA_AddPrefab.AddPrefab.create_add_gold();
                break;
            case "bank":
                AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_yinhang_mianban();
                break;
            case "mission":
                AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_renwu_mianban();
                break;
            case "online":
                AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_zaixianlibao_mianban();
                break;
            case "share":
                AL_GAME_HUA_Common.Common.share({
                    location: AL_GAME_HUA_Define.Define.SHARE_LOCATION.HOME,
                    type: 1
                });
                break;
            case "welfare":
                AL_GAME_HUA_AddPrefab.AddPrefab.chuangjian_fuli_mianban();
                break;
        }
    }

    /**
     * 更新UI
     */
    update() {
        this.shuaxin_zaixian_biaoqian();
    }
}

export default MainScene;